package com.ww.learn.type

class Animals(val age: Int) {
    override operator fun equals(other: Any?): Boolean {
        return if (other is Animals) age == other.age else false
    }
}

fun main() {
//    val greet: Any = "hello"
//    val odie: Any = Animals()
//    val toto: Any = Animals()

    // 使用==运算符访问equals()方法
//    false
//    true
//    println(odie == greet)
//    println(odie == toto)

    // 增加age属性之后代码
    val odie = Animals(2)
    val toto = Animals(2)
    val butch = Animals(3)

//    true
//    false
    println(odie == toto)
    println(butch == toto)
}